package com.zhoutao.blog.seven.model.detail;

import com.zhoutao.blog.seven.model.response.Article;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class ArticleDetail extends Article {

    private String categoryIcon;
    private String categoryTitle;
    private List<String> tags = Collections.emptyList();

    public ArticleDetail(Article article) {
        BeanUtils.copyProperties(article, this);
        String keys = this.getKeys();
        if (StringUtils.hasText(keys)) {
            String[] tagStr = keys.split(";");
            this.tags = Arrays.asList(tagStr);
        }
    }

    public String findIcon() {
        if (this.getIcon() != null && this.getIcon().trim().length() > 0) {
            return this.getIcon().trim();
        }
        return this.categoryIcon;
    }

}
